home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Programming Tools / Pascal Demos from Apple / qd samples / QDSAMPLE.TEXT next >
Encoding:
Text File  |  1984-06-23  |  19.7 KB  |  671 lines  |  [TEXT/ttxt]

  1. {$X-}
  2. PROGRAM QDSample;
  3.  
  4.   { QDSample -- Macintosh adaptation of Lisa QuickDraw example. }
  5.   { by Paul Zemlin, Macintosh Technical Support                 }
  6.  
  7.    USES {$U-}
  8.       {$U Obj/Memtypes    } Memtypes,
  9.       {$U Obj/QuickDraw   } QuickDraw,
  10.       {$U Obj/OSIntf      } OSIntf,
  11.       {$U Obj/ToolIntf    } ToolIntf;
  12.  
  13. TYPE  IconData = ARRAY[0..95] OF INTEGER;
  14.  
  15.    CONST
  16.       lastMenu = 2;   { number of menus }
  17.       appleMenu = 1;  { menu ID for desk accessory menu }
  18.       fileMenu = 256; { menu ID for File menu }
  19.  
  20.    VAR
  21.       myMenus                           : ARRAY [1..lastMenu] OF MenuHandle;
  22.       dragRect ,prect, growrect         : Rect;
  23.       doneFlag,temp                     : BOOLEAN;
  24.       myEvent                           : EventRecord;
  25.       code, refNum, MyControl,t         : INTEGER;
  26.       theMenu, theItem, whichIcon       : INTEGER;
  27.       scale                             : INTEGER;
  28.       wRecord                           : WindowRecord;
  29.       theWindow, whichWindow            : WindowPtr;
  30.       icons                             : ARRAY[0..5] OF IconData;
  31.       hScroll, vScroll, whichControl    : ControlHandle;
  32.       theOrigin                         : Point;
  33.       theUpdateRgn                      : RgnHandle;
  34.  
  35.  
  36.    PROCEDURE InitIcons;
  37.    { Manually stuff some icons.  Normally we would read them from a file }
  38.    BEGIN
  39.      { Lisa }
  40.      StuffHex(@icons[0, 0],'000000000000000000000000000000000000001FFFFFFFFC');
  41.      StuffHex(@icons[0,12],'00600000000601800000000B0600000000130FFFFFFFFFA3');
  42.      StuffHex(@icons[0,24],'18000000004311FFFFF00023120000080F231200000BF923');
  43.      StuffHex(@icons[0,36],'120000080F23120000080023120000080023120000080F23');
  44.      StuffHex(@icons[0,48],'1200000BF923120000080F2312000008002311FFFFF00023');
  45.      StuffHex(@icons[0,60],'08000000004307FFFFFFFFA30100000000260FFFFFFFFE2C');
  46.      StuffHex(@icons[0,72],'18000000013832AAAAA8A9F0655555515380C2AAAA82A580');
  47.      StuffHex(@icons[0,84],'800000000980FFFFFFFFF300800000001600FFFFFFFFFC00');
  48.  
  49.      { Printer }
  50.      StuffHex(@icons[1, 0],'000000000000000000000000000000000000000000000000');
  51.      StuffHex(@icons[1,12],'00000000000000007FFFFF00000080000280000111514440');
  52.      StuffHex(@icons[1,24],'0002000008400004454510400004000017C00004A5151000');
  53.      StuffHex(@icons[1,36],'0004000010000004A54510000004000017FE00F4A5151003');
  54.      StuffHex(@icons[1,48],'0184000013870327FFFFF10F06400000021B0CFFFFFFFC37');
  55.      StuffHex(@icons[1,60],'18000000006B3000000000D77FFFFFFFFFABC00000000356');
  56.      StuffHex(@icons[1,72],'8000000001AC87F000000158841000CCC1B087F000CCC160');
  57.      StuffHex(@icons[1,84],'8000000001C0C000000003807FFFFFFFFF0007800001E000');
  58.  
  59.      { Trash Can }
  60.      StuffHex(@icons[2, 0],'000001FC000000000E0600000000300300000000C0918000');
  61.      StuffHex(@icons[2,12],'00013849800000026C4980000004C0930000000861260000');
  62.      StuffHex(@icons[2,24],'0010064FE0000031199830000020E6301800002418E00800');
  63.      StuffHex(@icons[2,36],'0033E3801C0000180E002C00000FF801CC0000047FFE0C00');
  64.      StuffHex(@icons[2,48],'000500004C000005259A4C000005250A4C00000525FA4C00');
  65.      StuffHex(@icons[2,60],'000524024C00000524924C00600524924C0090E524924C7C');
  66.      StuffHex(@icons[2,72],'932524924C82A44524924D01C88524924CF10C4524924C09');
  67.      StuffHex(@icons[2,84],'0784249258E70003049233100000E000E40800001FFFC3F0');
  68.  
  69.      { tray }
  70.      StuffHex(@icons[3, 0],'000000000000000000000000000000000000000000000000');
  71.      StuffHex(@icons[3,12],'0000000000000000000000000000000000000007FFFFFFF0');
  72.      StuffHex(@icons[3,24],'000E00000018001A00000038003600000078006A000000D8');
  73.      StuffHex(@icons[3,36],'00D7FFFFFFB801AC000003580358000006B807FC000FFD58');
  74.      StuffHex(@icons[3,48],'040600180AB80403FFF00D58040000000AB8040000000D58');
  75.      StuffHex(@icons[3,60],'040000000AB807FFFFFFFD5806AC00000AB8055800000D58');
  76.      StuffHex(@icons[3,72],'06B000000AB807FC000FFD70040600180AE00403FFF00DC0');
  77.      StuffHex(@icons[3,84],'040000000B80040000000F00040000000E0007FFFFFFFC00');
  78.  
  79.      { File Cabinet }
  80.      StuffHex(@icons[4, 0],'0007FFFFFC00000800000C00001000001C00002000003400');
  81.      StuffHex(@icons[4,12],'004000006C0000FFFFFFD40000800000AC0000BFFFFED400');
  82.      StuffHex(@icons[4,24],'00A00002AC0000A07F02D40000A04102AC0000A07F02D400');
  83.      StuffHex(@icons[4,36],'00A00002AC0000A08082D40000A0FF82AC0000A00002D400');
  84.      StuffHex(@icons[4,48],'00A00002AC0000BFFFFED40000800000AC0000BFFFFED400');
  85.      StuffHex(@icons[4,60],'00A00002AC0000A07F02D40000A04102AC0000A07F02D400');
  86.      StuffHex(@icons[4,72],'00A00002AC0000A08082D40000A0FF82AC0000A00002D800');
  87.      StuffHex(@icons[4,84],'00A00002B00000BFFFFEE00000800000C00000FFFFFF8000');
  88.  
  89.      { drawer }
  90.      StuffHex(@icons[5, 0],'000000000000000000000000000000000000000000000000');
  91.      StuffHex(@icons[5,12],'000000000000000000000000000000000000000000000000');
  92.      StuffHex(@icons[5,24],'000000000000000000000000000000000000000000000000');
  93.      StuffHex(@icons[5,36],'00000000000000000000000000000000000000001FFFFFF0');
  94.      StuffHex(@icons[5,48],'0000380000300000680000700000D80000D0003FFFFFF1B0');
  95.      StuffHex(@icons[5,60],'0020000013500020000016B000201FE01D50002010201AB0');
  96.      StuffHex(@icons[5,72],'00201FE01560002000001AC0002000001580002020101B00');
  97.      StuffHex(@icons[5,84],'00203FF01600002000001C00002000001800003FFFFFF000');
  98.  
  99.    END;
  100.  
  101.  
  102.    PROCEDURE DrawIcon(whichIcon,h,v: INTEGER);  {DrawAnIcon => DrawIcon}
  103.    VAR
  104.        srcBits           : BitMap;
  105.        srcRect, dstRect  : Rect;
  106.  
  107.    BEGIN
  108.      srcBits.baseAddr:=@icons[whichIcon];
  109.      srcBits.rowBytes:=6;
  110.      SetRect(srcBits.bounds,0,0,48,32);
  111.      srcRect:=srcBits.bounds;
  112.      dstRect:=srcRect;
  113.      OffsetRect(dstRect,h,v);
  114.      CopyBits(srcBits,theWindow^.portBits,srcRect,dstRect,srcOr,Nil);
  115.    END;
  116.  
  117.  
  118.    PROCEDURE DrawStuff;
  119.    VAR i: INTEGER;
  120.        tempRect   : Rect;
  121.        myPoly     : PolyHandle;
  122.        myRgn      : RgnHandle;
  123.        myPattern  : Pattern;
  124.  
  125.    BEGIN
  126.  
  127.      StuffHex(@myPattern,'8040200002040800');
  128.  
  129.      { draw two horizontal lines across the top }
  130.      MoveTo(0,18);
  131.      LineTo(719,18);
  132.      MoveTo(0,20);
  133.      LineTo(719,20);
  134.  
  135.      { draw divider lines }
  136.      MoveTo(0,134);
  137.      LineTo(719,134);
  138.      MoveTo(0,248);
  139.      LineTo(719,248);
  140.      MoveTo(240,21);
  141.      LineTo(240,363);
  142.      MoveTo(480,21);
  143.      LineTo(480,363);
  144.  
  145.      { draw title }
  146.      TextFont(0);
  147.      MoveTo(210,14);
  148.      DrawString('Look what you can draw with QuickDraw');
  149.  
  150.  
  151.  
  152.      {---------  draw text samples --------- }
  153.  
  154.      MoveTo(80,34);  DrawString('Text');
  155.  
  156.      TextFace([bold]);
  157.      MoveTo(70,55);  DrawString('Bold');
  158.  
  159.      TextFace([italic]);
  160.      MoveTo(70,70); DrawString('Italic');
  161.  
  162.      TextFace([underline]);
  163.      MoveTo(70,85); DrawString('Underline');
  164.  
  165.      TextFace([outline]);
  166.      MoveTo(70,100); DrawString('Outline');
  167.  
  168.      TextFace([shadow]);
  169.      MoveTo(70,115); DrawString('Shadow');
  170.  
  171.      TextFace([]);   { restore to normal }
  172.  
  173.  
  174.  
  175.      { --------- draw line samples --------- }
  176.  
  177.      MoveTo(330,34);  DrawString('Lines');
  178.  
  179.      MoveTo(280,25);  Line(160,40);
  180.  
  181.      PenSize(3,2);
  182.      MoveTo(280,35);  Line(160,40);
  183.  
  184.      PenSize(6,4);
  185.      MoveTo(280,46);  Line(160,40);
  186.  
  187.      PenSize(12,8);
  188.      PenPat(gray);
  189.      MoveTo(280,61); Line(160,40);
  190.  
  191.      PenSize(15,10);
  192.      PenPat(myPattern);
  193.      MoveTo(280,80); Line(160,40);
  194.      PenNormal;
  195.  
  196.  
  197.  
  198.      { --------- draw rectangle samples --------- }
  199.  
  200.      MoveTo(560,34);  DrawString('Rectangles');
  201.  
  202.      SetRect(tempRect,510,40,570,70);
  203.      FrameRect(tempRect);
  204.  
  205.      OffsetRect(tempRect,25,15);
  206.      PenSize(3,2);
  207.      EraseRect(tempRect);
  208.      FrameRect(tempRect);
  209.  
  210.      OffsetRect(tempRect,25,15);
  211.      PaintRect(tempRect);
  212.  
  213.      OffsetRect(tempRect,25,15);
  214.      PenNormal;
  215.      FillRect(tempRect,gray);
  216.      FrameRect(tempRect);
  217.  
  218.      OffsetRect(tempRect,25,15);
  219.      FillRect(tempRect,myPattern);
  220.      FrameRect(tempRect);
  221.  
  222.  
  223.      { --------- draw roundRect samples --------- }
  224.  
  225.      MoveTo(70,148);  DrawString('RoundRects');
  226.  
  227.      SetRect(tempRect,30,150,90,180);
  228.      FrameRoundRect(tempRect,30,20);
  229.  
  230.      OffsetRect(tempRect,25,15);
  231.      PenSize(3,2);
  232.      EraseRoundRect(tempRect,30,20);
  233.      FrameRoundRect(tempRect,30,20);
  234.  
  235.      OffsetRect(tempRect,25,15);
  236.      PaintRoundRect(tempRect,30,20);
  237.  
  238.      OffsetRect(tempRect,25,15);
  239.      PenNormal;
  240.      FillRoundRect(tempRect,30,20,gray);
  241.      FrameRoundRect(tempRect,30,20);
  242.  
  243.      OffsetRect(tempRect,25,15);
  244.      FillRoundRect(tempRect,30,20,myPattern);
  245.      FrameRoundRect(tempRect,30,20);
  246.  
  247.  
  248.      { --------- draw bitmap samples --------- }
  249.  
  250.      MoveTo(320,148);  DrawString('BitMaps');
  251.  
  252.      DrawIcon(0,266,156);
  253.      DrawIcon(1,336,156);
  254.      DrawIcon(2,406,156);
  255.      DrawIcon(3,266,196);
  256.      DrawIcon(4,336,196);
  257.      DrawIcon(5,406,196);
  258.  
  259.  
  260.      { --------- draw ARC samples --------- }
  261.  
  262.      MoveTo(570,148);  DrawString('Arcs');
  263.  
  264.      SetRect(tempRect,520,153,655,243);
  265.      FillArc(tempRect,135,65,dkGray);
  266.      FillArc(tempRect,200,130,myPattern);
  267.      FillArc(tempRect,330,75,gray);
  268.      FrameArc(tempRect,135,270);
  269.      OffsetRect(tempRect,20,0);
  270.      PaintArc(tempRect,45,90);
  271.  
  272.  
  273.      { --------- draw polygon samples --------- }
  274.  
  275.      MoveTo(80,262);  DrawString('Polygons');
  276.  
  277.      myPoly:=OpenPoly;
  278.        MoveTo(30,290);
  279.        LineTo(30,280);
  280.        LineTo(50,265);
  281.        LineTo(90,265);
  282.        LineTo(80,280);
  283.        LineTo(95,290);
  284.        LineTo(30,290);
  285.      ClosePoly;       { end of definition }
  286.  
  287.      FramePoly(myPoly);
  288.  
  289.      OffsetPoly(myPoly,25,15);
  290.      PenSize(3,2);
  291.      ErasePoly(myPoly);
  292.      FramePoly(myPoly);
  293.  
  294.      OffsetPoly(myPoly,25,15);
  295.      PaintPoly(myPoly);
  296.  
  297.      OffsetPoly(myPoly,25,15);
  298.      PenNormal;
  299.      FillPoly(myPoly,gray);
  300.      FramePoly(myPoly);
  301.  
  302.      OffsetPoly(myPoly,25,15);
  303.      FillPoly(myPoly,myPattern);
  304.      FramePoly(myPoly);
  305.  
  306.      KillPoly(myPoly);
  307.  
  308.  
  309.      { --------- demonstrate regions --------- }
  310.  
  311.      MoveTo(320,262);  DrawString('Regions');
  312.  
  313.      myRgn:=NewRgn;
  314.      OpenRgn;
  315.        ShowPen;
  316.  
  317.        SetRect(tempRect,260,270,460,350);
  318.        FrameRoundRect(tempRect,24,16);
  319.  
  320.        MoveTo(275,335);  { define triangular hole }
  321.        LineTo(325,285);
  322.        LineTo(375,335);
  323.        LineTo(275,335);
  324.  
  325.        SetRect(tempRect,365,277,445,325);   { oval hole }
  326.        FrameOval(tempRect);
  327.  
  328.        HidePen;
  329.      CloseRgn(myRgn);       { end of definition }
  330.      DisposeRgn(myRgn);
  331.  
  332.  
  333.      { --------- draw oval samples --------- }
  334.  
  335.      MoveTo(580,262);  DrawString('Ovals');
  336.  
  337.      SetRect(tempRect,510,264,570,294);
  338.      FrameOval(tempRect);
  339.  
  340.      OffsetRect(tempRect,25,15);
  341.      PenSize(3,2);
  342.      EraseOval(tempRect);
  343.      FrameOval(tempRect);
  344.  
  345.      OffsetRect(tempRect,25,15);
  346.      PaintOval(tempRect);
  347.  
  348.      OffsetRect(tempRect,25,15);
  349.      PenNormal;
  350.      FillOval(tempRect,gray);
  351.      FrameOval(tempRect);
  352.  
  353.      OffsetRect(tempRect,25,15);
  354.      FillOval(tempRect,myPattern);
  355.      FrameOval(tempRect);
  356.  
  357.    END;  { DrawStuff }
  358.  
  359.  
  360.    PROCEDURE MoveScrollBars;
  361.  
  362.       BEGIN
  363.          WITH theWindow^.portRect DO
  364.             BEGIN
  365.             HideControl(vScroll);
  366.             MoveControl(vScroll,right-15,top-1);
  367.             SizeControl(vScroll,16,bottom-top-13);
  368.             ShowControl(vScroll);
  369.             HideControl(hScroll);
  370.             MoveControl(hScroll,left-1,bottom-15);
  371.             SizeControl(hScroll,right-left-13,16);
  372.             ShowControl(hScroll)
  373.             END
  374.       END;
  375.  
  376.    PROCEDURE ResizePRect;
  377.  
  378.    { pRect is the window's content region, minus the scroll bars }
  379.  
  380.       BEGIN
  381.          pRect := thePort^.portRect;
  382.          pRect.right := pRect.right-15;
  383.          pRect.bottom := pRect.bottom-15
  384.       END;
  385.  
  386.    PROCEDURE GrowWnd (whichWindow: WindowPtr);
  387.  
  388.    { Handles growing and sizing the window and manipulating }
  389.    { the update region. }
  390.  
  391.       VAR
  392.          longResult: LongInt;
  393.          height,width: INTEGER;
  394.          tRect: Rect;
  395.  
  396.       BEGIN
  397.          longResult := GrowWindow(whichWindow,myEvent.where,growRect);
  398.          IF longResult=0 THEN EXIT(GrowWnd);
  399.          height := HiWord(longResult); width := LoWord(longResult);
  400.  
  401.          { Add the old "scroll bar area" to the update region so it will }
  402.          { be redrawn (for when the window is enlarged). }
  403.          tRect := whichWindow^.portRect;
  404.          tRect.left := tRect.right - 16;
  405.          InvalRect(tRect);
  406.          tRect := whichWindow^.portRect;
  407.          tRect.top := tRect.bottom - 16;
  408.          InvalRect(tRect);
  409.  
  410.  
  411.          { Now draw the newly sized window. }
  412.          SizeWindow(whichWindow,width,height,TRUE);
  413.          MoveScrollBars;
  414.          ResizePRect;
  415.  
  416.          { Add the new "scroll bar area" to the update region so it will }
  417.          { be redrawn (for when the window is made smaller). }
  418.          tRect := whichWindow^.portRect; tRect.left := tRect.right-16;
  419.          InvalRect(tRect);
  420.          tRect := whichWindow^.portRect; tRect.top := tRect.bottom-16;
  421.          InvalRect(tRect);
  422.       END; { of GrowWnd }
  423.  
  424.    PROCEDURE DrawWindow(whichWindow: WindowPtr);
  425.    { Draws the content region of theWindow }
  426.  
  427.       VAR
  428.          tRect    : Rect;
  429.  
  430.       BEGIN
  431.  
  432.          ClipRect (theWindow^.portRect);
  433.          DrawGrowIcon(theWindow);
  434.          IF theWindow = FrontWindow THEN DrawControls(theWindow);
  435.  
  436.          { Now set up a clip area which excludes the scroll bars }
  437.  
  438.  
  439.          tRect := theWindow^.portRect;
  440.          tRect.bottom := tRect.bottom - 16;
  441.          tRect.right := tRect.right - 16;
  442.  
  443.          {Now compensate for any scrolling which has been done }
  444.  
  445.          OffsetRect (tRect, theOrigin.h, theOrigin.v);
  446.          ClipRect (tRect);
  447.  
  448.          { Change the origin to compensate for any scrolling which has been done }
  449.  
  450.          SetOrigin (theOrigin.h, theOrigin.v);
  451.          DrawStuff;
  452.          SetOrigin (0, 0);
  453.          ClipRect (theWindow^.portRect);  { Reset the clip area }
  454.        END; { of DrawWindow }
  455.  
  456.    PROCEDURE ScrollBits;
  457.  
  458.       VAR
  459.          oldOrigin   : point;
  460.          dh,dv       : INTEGER;
  461.          tRect       : Rect;
  462.  
  463.       BEGIN
  464.             oldOrigin := theOrigin;
  465.             theOrigin.h := 4 * GetCtlValue(hScroll);
  466.             theOrigin.v := 4 * GetCtlValue(vScroll);
  467.             dh := oldOrigin.h - theOrigin.h;
  468.             dv := oldOrigin.v - theOrigin.v;
  469.             theUpdateRgn := NewRgn;
  470.             ScrollRect (pRect, dh, dv, theUpdateRgn);
  471.  
  472.             { Have scrolled in junk...need to redraw }
  473.  
  474.             SetOrigin (theOrigin.h, theOrigin.v);
  475.             OffsetRect (theUpdateRgn^^.rgnBBox, theOrigin.h, theOrigin.v);
  476.             ClipRect (theUpdateRgn^^.rgnBBox);
  477.             DrawStuff;
  478.             DisposeRgn (theUpdateRgn);
  479.             SetOrigin (0, 0);
  480.             ClipRect (theWindow^.portRect);
  481.       END;
  482.  
  483.    PROCEDURE ScrollUp(whichControl: ControlHandle; theCode: INTEGER);
  484.  
  485.       BEGIN
  486.          IF theCode=inUpButton THEN
  487.             BEGIN
  488.             SetCtlValue(whichControl,GetCtlValue(whichControl)-1);
  489.             ScrollBits
  490.             END
  491.       END;
  492.  
  493.    PROCEDURE ScrollDown(whichControl: ControlHandle; theCode: INTEGER);
  494.  
  495.       BEGIN
  496.          IF theCode=inDownButton THEN
  497.             BEGIN
  498.             SetCtlValue(whichControl,GetCtlValue(whichControl)+1);
  499.             ScrollBits
  500.             END
  501.       END;
  502.  
  503.    PROCEDURE PageScroll(code,amount: INTEGER);
  504.  
  505.       VAR
  506.          myPt: point;
  507.  
  508.       BEGIN
  509.          REPEAT
  510.             GetMouse(myPt);
  511.             IF TestControl(whichControl,myPt)=code THEN
  512.                BEGIN
  513.                SetCtlValue(whichControl,GetCtlValue(whichControl)+amount);
  514.                ScrollBits
  515.                END
  516.          UNTIL NOT StillDown;
  517.       END;
  518.  
  519.    PROCEDURE SetUpMenus;
  520.    { Once-only initialization for menus }
  521.  
  522.       VAR
  523.          i: INTEGER;
  524.  
  525.       BEGIN
  526.          InitMenus; { initialize Menu Manager }
  527.          myMenus[1] := GetMenu(appleMenu);
  528.          AddResMenu(myMenus[1],'DRVR'); { desk accessories }
  529.          myMenus[2] := GetMenu(fileMenu);
  530.          FOR i := 1 TO lastMenu DO InsertMenu(myMenus[i],0);
  531.          DrawMenuBar;
  532.       END; { of SetUpMenus }
  533.  
  534.  
  535.    PROCEDURE DoCommand(mResult: LongInt);
  536.  
  537.       VAR
  538.          name: STR255;
  539.  
  540.       BEGIN
  541.          theMenu := HiWord(mResult); theItem := LoWord(mResult);
  542.          CASE theMenu OF
  543.  
  544.             appleMenu:
  545.                BEGIN
  546.                GetItem(myMenus[1],theItem,name);
  547.                refNum := OpenDeskAcc(name);
  548.                END;
  549.  
  550.             fileMenu: doneFlag := TRUE; { Quit }
  551.  
  552.  
  553.          END; { of menu case }
  554.  
  555.          HiliteMenu(0);
  556.  
  557.       END; { of DoCommand }
  558.  
  559.    BEGIN { main program }
  560.       InitGraf(@thePort);
  561.       InitFonts;
  562.       FlushEvents(everyEvent,0);
  563.       InitWindows;
  564.       SetUpMenus;
  565.       InitDialogs(NIL);
  566.       SetCursor(arrow);
  567.       SetRect(dragRect,4,24,508,338);
  568.       SetRect(growRect,100,60,512,302);
  569.       doneFlag := FALSE;
  570.       InitCursor;
  571.       InitIcons;
  572.  
  573.       theWindow := GetNewWindow(256,@wRecord,POINTER(-1));
  574.       SetPort(theWindow);
  575.       theWindow^.txFont := 2;
  576.  
  577.       ResizePRect;
  578.  
  579.       vScroll := GetNewControl(256,theWindow);
  580.       hScroll := GetNewControl(257,theWindow);
  581.       theOrigin.h := 0; theOrigin.v := 0;
  582.  
  583.  
  584.       REPEAT
  585.          SystemTask;
  586.          temp := GetNextEvent(everyEvent,myEvent);
  587.          CASE myEvent.what OF
  588.  
  589.             mouseDown:
  590.                BEGIN
  591.                code := FindWindow(myEvent.where,whichWindow);
  592.                CASE code OF
  593.  
  594.                   inMenuBar: DoCommand(MenuSelect(myEvent.where));
  595.  
  596.                   inSysWindow: SystemClick(myEvent,whichWindow);
  597.  
  598.                   inDrag: DragWindow(whichWindow,myEvent.where,dragRect);
  599.  
  600.                   inGoAway:
  601.                      IF TrackGoAway(whichWindow,myEvent.where) THEN
  602.                         doneFlag := TRUE;
  603.  
  604.                   inGrow:
  605.                      IF whichWindow=FrontWindow THEN
  606.                         GrowWnd(whichWindow)
  607.                      ELSE
  608.                         SelectWindow(whichWindow);
  609.  
  610.                   inContent:
  611.                      BEGIN
  612.                      IF whichWindow<>FrontWindow THEN
  613.                         SelectWindow(whichWindow)
  614.                      ELSE
  615.                         BEGIN {front}
  616.                         GlobalToLocal(myEvent.where);
  617.                         IF  NOT PtInRect(myEvent.where,pRect) THEN
  618.                            BEGIN {controls}
  619.                            MyControl := FindControl(myEvent.where,whichWindow,
  620.                                                     whichControl);
  621.                            CASE MyControl OF
  622.                               inUpButton:
  623.                                  t := TrackControl(whichControl,myEvent.where,
  624.                                                    @ScrollUp);
  625.                               inDownButton:
  626.                                  t := TrackControl(whichControl,myEvent.where,
  627.                                                    @ScrollDown);
  628.                               inPageUP: PageScroll(MyControl,-10);
  629.                               inPageDown: PageScroll(MyControl,10);
  630.                               inThumb:
  631.                                  BEGIN
  632.                                  t := TrackControl(whichControl,myEvent.where,
  633.                                       NIL);
  634.                                  ScrollBits
  635.                                  END
  636.                            END {Case MyControl}
  637.                            END {controls}
  638.                         END {front}
  639.                      END {in Content}
  640.                END; { of code case }
  641.                END; { of mouseDown }
  642.  
  643.             activateEvt:
  644.                BEGIN
  645.                SetPort (theWindow);
  646.                DrawGrowIcon(theWindow);
  647.                IF ODD(myEvent.modifiers) THEN { window is becoming active }
  648.                   BEGIN
  649.                   ShowControl(vScroll);
  650.                   ShowControl(hScroll);
  651.                   END
  652.                ELSE
  653.                   BEGIN
  654.                   HideControl(vScroll);
  655.                   HideControl(hScroll)
  656.                   END
  657.                END; { of activateEvt }
  658.  
  659.             updateEvt:
  660.                BEGIN
  661.                BeginUpdate(theWindow);
  662.                EraseRect (theWindow^.portRect);
  663.                DrawWindow(theWindow);
  664.                EndUpdate(theWindow);
  665.                END { of updateEvt }
  666.  
  667.          END { of event case }
  668.  
  669.       UNTIL doneFlag
  670.    END.
  671.